package cn.tedu.logistics.utils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;

public class BeanValidate {

	public static boolean checkNull(Object obj) {//检验属性中是否存在空值
		try {
			Field[] fields = obj.getClass().getDeclaredFields();
			String name;
			for(int i=0;i<fields.length;i++) {
				name = fields[i].getName();
				String type = fields[i].getGenericType().toString(); //获取属性类型
				String getter = "get"+name.substring(0,1).toUpperCase()+name.substring(1);
				Method m = obj.getClass().getMethod(getter);
				String value = m.invoke(obj).toString();
				if(StringUtils.isEmpty(value)) { 
					return true;
				}
			}
		}catch (Exception e) {
			e.printStackTrace();
			return true;
		}
		return false;
	}
}
